package com.ruoyi.report.controller;

import com.ruoyi.api.system.utils.ShiroUtils;
import com.ruoyi.api.system.utils.poi.ExcelUtil;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.record.domain.RecordBenefitContent;
import com.ruoyi.report.domain.ReportAttend;
import com.ruoyi.report.domain.ReportSalary;
import com.ruoyi.report.service.IReportAttendService;
import com.ruoyi.report.service.IReportSalaryService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Calendar;
import java.util.List;

/**
 * 考勤汇总 Controller
 *
 * @author ruoyi
 * @date 2022-09-26
 */
@Controller
@RequestMapping("/report/salary")
public class ReportSalaryController extends BaseController {

    private String prefix = "report/salary";

    @Autowired
    private IReportSalaryService reportSalaryService;

    @GetMapping()
    public String salary(ModelMap mmap)
    {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.MONTH, -1);
        mmap.put("startMonth", DateUtils.getYear() + "-01");
        mmap.put("endMonth", DateUtils.getMonth());
        return prefix + "/salary";
    }

    /**
     * 查询考勤统计
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ReportSalary reportSalary)
    {
        startPage();
        List<ReportSalary> list = reportSalaryService.selectReportSalaryList(reportSalary);
        return getDataTable(list);
    }

    /**
     * 导出保险金内容列表
     */
    @Log(title = "工资统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ReportSalary reportSalary)
    {
        List<ReportSalary> list = reportSalaryService.selectReportSalaryList(reportSalary);
        ExcelUtil<ReportSalary> util = new ExcelUtil<ReportSalary>(ReportSalary.class);
        return util.exportExcel(list, "工资统计");
    }
}
